import { Component, OnInit } from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd/message';
import {Service} from '../service/service';

@Component({
  selector: 'app-express',
  templateUrl: './express.component.html',
  styleUrls: ['./express.component.scss']
})
export class ExpressComponent implements OnInit {
  constructor(private service: Service, private msg: NzMessageService) {
    this.getAllExpress();
  }
  searchStatus = 0;
  listOfStatus = [{ text: '已审核', value: '1' }, { text: '未审核', value: '0' }];
  listOfData: Array<{ name: string; address: string; description: string; money: number, opentime: string , phone: number,
    status: number,
    uid: number,
    update_time: string}> = [];
  listOfDisplayData: Array<{ name: string; address: string; description: string; money: number, opentime: string , phone: number,
    status: number,
    uid: number,
    update_time: string}> = [
    ...this.listOfData
  ];


  filter(value: number): void {
    this.searchStatus = +value;
    this.search();
  }

  search(): void {
    console.log(this.searchStatus);
    const data = this.listOfData.filter(item => {
      if ( this.searchStatus == item.status){
        return true;
      }
    });
    this.listOfDisplayData = data;
  }

  getAllExpress() {
    this.service.getAllExpress(null, (result) => {
      this.listOfData = result.data;
      this.listOfDisplayData = [...this.listOfData];
    });
  }
  check(id){
    const data = {
      id
    };
    this.service.getAllCheck(data, (result) => {
      if (result.status == 1){
        this.msg.info('审核成功');
      }else{
        this.msg.error('审核失败');
      }
      this.getAllExpress();
    });
  }
  ngOnInit(): void {
  }
}
